<?php

namespace Modules\System\Services\Mds;

class MDSString
{

    /**
     * 获取唯一token字符串
     **/
    static public function getToken($length,$seed){

        $token = "";
        $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $codeAlphabet .= "0123456789";

        mt_srand($seed);      // Call once. Good since $application_id is unique.

        for($i = 0;$i < $length;$i++){
            $token .= $codeAlphabet[mt_rand(0,strlen($codeAlphabet) - 1)];
        }
        return $token;

    }

    /**
     * 判断该字符串是否为 Json格式
     **/
    static public function isJsonBool($data = '',$assoc = false){
        $data = json_decode($data,$assoc);
        if(($data && is_object($data)) || (is_array($data) && !empty($data))){
            return $data;
        }
        return false;
    }

    /**
     * 判断一个字符串是否包含另一个字符处
     **/
    static public function contain($body,$str){
        if(strpos(strtolower($body),strtolower($str)) !== false){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 判断一个字符串是否包含另一个数组中含有的字符串
     **/
    static public function arrContain($arr,$str){
        foreach($arr as $k=>$v){
            if(self::contain($str,$v)){
                return true;
            }
        }
        return false;
    }

}